<template>
  <div class="wrapper">
    <!-- 通过v-if 使用完整的数据创建不会导致默认显示最后一张 -->
    <swiper ref="mySwiper" :options="swiperOptions" v-if="showSwiper">
         
    <swiper-slide v-for="item of list" :key="item.id"><img class="swiper-img" :src="item.imgUrl"></swiper-slide>
    <div class="swiper-pagination" slot="pagination"></div>
   </swiper>
  </div>
</template>
 
<script>
  export default {
    name: 'HomeSwiper',
    props:{
      list:Array
    },
    data() {
      return {
        swiperOptions: {
          loop: true,
          pagination: {
            el: '.swiper-pagination'
          },
          autoplay: {
                delay: 1500,
                stopOnLastSlide: false,
                disableOnInteraction: false 
            }

        },
      }
    },
    computed: {
      showSwiper(){
        return this.list.length
      }
    },
    mounted() {
    //   console.log('Current Swiper instance object', this.swiper)
        
    //   this.swiper.slideTo(3, 1000, true)
    }
  }
</script> 

<style lang="stylus" scoped>
  .wrapper >>> .swiper-pagination-bullet-active
    background #fff
  .wrapper
    overflow hidden
    width 100%
    height 0
    padding-bottom 31.25%
    .swiper-pagination-bullets
    // 修复bug把按钮拉回来
        top 0px
    .swiper-img
        width 100%
       
</style>